package com.frame.work.frame.deal.device0fe6;

import com.alibaba.fastjson.JSONObject;
import com.frame.work.common.util.JsonToMqtt;
import com.frame.work.frame.deal.base.BaseFrame;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

import static com.frame.work.common.constant.CallType.*;

/**
 * 静音窗帘0FE60209
 */
@Data
public class JingYinChuangLian_0FE60209 extends BaseFrame {

    private String switchState;

    public JingYinChuangLian_0FE60209(String gatewayMac, String data, String type) {

        //将基础数据进行处理
        super(gatewayMac, data);

        //根据不同类型进行判断
        if (TYPE_01.equals(type)) {
            JingYinChuangLian_0FE60209_01(gatewayMac, data);
        } else if (TYPE_07.equals(type)) {
            JingYinChuangLian_0FE60209_07(gatewayMac, data);
        }

    }


    public void JingYinChuangLian_0FE60209_01(String gatewayMac, String data) {
        //处理此设备特有的数据
        this.setSwitchState("");

        //将actions信息放入json对象中
        Map<String, Object> actions = new HashMap();
        this.setActions(actions);

        //处理好的json对象
        String json = JSONObject.toJSONString(this);
        //将数据发送到mqtt队列中
        JsonToMqtt.sendMQTT(gatewayMac, json);
    }

    public void JingYinChuangLian_0FE60209_07(String gatewayMac, String data) {

        //将基础数据进行处理
        this.setGatewayMac(gatewayMac);
        this.setDeviceMac(StringUtils.substring(data, 2, 18));
        this.setOdIndex(StringUtils.substring(data, 18, 22));
        this.setDeviceType(StringUtils.substring(data, 22, 24));
        this.setProductType(StringUtils.substring(data, 24, 26));

        String cmd_head = StringUtils.substring(data, 36, 44);
        String cmd_type = StringUtils.substring(data, 48, 52);
        String position = StringUtils.substring(data, 64, 66);

        if ("55AAAA55".equals(cmd_head) && "030A".equals(cmd_type)) {
            //将actions信息放入json对象中
            Map<String, Object> actions = new HashMap();
            actions.put("position", position);
            this.setActions(actions);

            //处理好的json对象
            String json = JSONObject.toJSONString(this);
            //将数据发送到mqtt队列中
            JsonToMqtt.sendMQTT(gatewayMac, json);

        }


    }


}
